package com.ruoyi.web.controller.business;

import com.ruoyi.service.IRegionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.po.Region;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 主题分区表 前端控制器
 * @author 杨宸
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/b/region")
@Api(tags = {"主题分区表控制器"})
public class RegionController {

    /**
     * 主题分区表业务接口
     */
    @Autowired
    private IRegionService baseService;

    /**
     * 描述：分页查询
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "分页查询")
    public R<IPage<Region>> pageList(@RequestBody Region region) {
        IPage<Region> pageVo = baseService.pageList(region);
        return R.ok(pageVo);
    }
    
    /**
     * 描述：详情
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public R<Region> detailRegion(@RequestBody Long id) {
        Region region = baseService.detailRegion(id);
        return R.ok(region);
    }    

    /**
     * 描述：保存
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/saveRegion")
    @ApiOperation(value = "保存")
    public R<String> saveRegion(@RequestBody Region region) {
        baseService.saveRegion(region);
        return R.ok("保存成功！");
    }

    /**
     * 描述：修改
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/updateRegion")
    @ApiOperation(value = "修改")
    public R<String> updateRegion(@RequestBody Region region) {
        baseService.updateRegion(region);
        return R.ok("修改成功！");
    }

    /**
     * 描述：删除
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/deleteRegion")
    @ApiOperation(value = "删除")
    public R<String> deleteRegion(@RequestBody List<Long> ids) {
        baseService.deleteRegion(ids);
        return R.ok("删除成功！");
    }

    /**
     * 描述：批量导出
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/exportExcel")
    @ApiOperation(value = "批量导出")
    public void exportExcel(HttpServletResponse response, @RequestBody Region region) {
        baseService.exportExcel(response, region);
    }

}
